<?php
	class MailModel extends Model{
		public $toid;
		public $fromid;
		public $title;
		public $content;
		public $CreateDate;
		
		public function __construct($toid,$fromid){
			$this->toid = intval($toid);
			$this->fromid = $fromid;
			$this->CreateDate = date('Y-m-d H:i:s',time());
		}
		
		public function sendmail(){
			$SenderName = $this->getname($this->fromid);
			$Receiver = $this->getname($this->toid);
			$title = $this->title;
			$content = $this->content;
			$Sender=$this->fromid;
			return $Model = M()->execute("
									insert into mail 
										(Id,Title,Content,Sender,IsDeleted,CreateDate,SenderName,Receiver,Receiverid,IsRead,Version)
									values 
										( NULL,'".$title."','".$content."',".$this->fromid.",'0','".$this->CreateDate."','".$SenderName."','".$Receiver."',".$this->toid.",'0','0')
								");
		}
		
		public function getname($uid){
			$name=M()->query('SELECT TrueName FROM users WHERE UserId ='.$uid);
			return $name[0]['TrueName'];
		}
		
		
	}
?>